package Top_Interview_Questions.Two_Pointers;

/**
 * @Author: 吕庆龙
 * @Date: 2020/3/11 15:59
 * <p>
 * 功能描述:
 */
public class _0125 {

    /**
     * 不使用库函数的做法,这篇题解下面有
     * https://leetcode-cn.com/problems/valid-palindrome/solution/valid-palindrome-shuang-zhi-zhen-fa-by-jyd/
     */
    public boolean isPalindrome(String s) {
        int i = 0, j = s.length() - 1;
        while(i < j){
            while(i < j && !Character.isLetterOrDigit(s.charAt(i)))
                i++;
            while(i < j && !Character.isLetterOrDigit(s.charAt(j)))
                j--;
            if(Character.toLowerCase(s.charAt(i)) != Character.toLowerCase(s.charAt(j)))
                return false;
            i++; j--;
        }
        return true;
    }

}
